[section .data]
position	dd	0
[section .text]
global memcpy
global	memset
global dispStr
global	dispChar
global in_byte
global	in_byteu8
global out_byte
global	cli
global  sti
global	none
global	interrupt
global	send2
global	recv2
;global	memcpy
;---------------memcpy(u32* src,u32* dest,u32 size)-----------;
;---------------复制内存地址数据------------------------------;
;memcpy:
;	push ebp
;	mov	ebp,esp
;	mov	ecx,dword[ebp+8] ;将大小加载到ecx寄存器中
;	mov	edi,dword[ebp+12] ;将目的地址加载到edi寄存器中
;	mov	esi,dword[ebp+16] ;将源地址加载到esi寄存器中
;	cld	;清方向性
;	rep	movsb  ;数据复制指令
;	pop	ebp
;	ret
;---------------memset(u32* addr,u32 size,u8 char)------------;
memset:
push	ebp
mov		ebp,esp
cld		;清方向性
xor		ecx,ecx ;清ecx寄存器的内容
mov		ecx,dword[ebp+12]   ;将大小加载到ecx寄存器中
xor		edi,edi ;清edi寄存器的内容
mov		edi,dword[ebp+8]	;将地址加载到edi寄存器中	
xor		eax,eax ;清eax寄存器的内容
mov		al,byte[ebp+16]  ;将字符加载到al中
rep		stosb	;将al寄存器的数据加载到ds:edi指向的地址
pop		ebp
ret
	
;----------发送消息函数--------------------------------;
;-----------send2(Message* msg)------------------------------;
send2:
	push	ebp
	mov		ebp,esp
	mov		eax,dword[ebp+8] ;将消息的地址放在寄存器eax中
	nop	
	int		60	;中断请求
	nop
	pop		ebp
	ret
;----------接收消息函数---------------------------------;
;----------recv2(Message* msg)-------------------------------;
recv2:
	push	ebp
	mov		ebp,esp
	mov		eax,dword[ebp+8] ;将消息的地址放在寄存器eax中
	int		61	;中断请求
	nop
	pop		ebp
	ret

interrupt:
	push	ebp
	mov	ebp,esp
	mov	eax,dword[ebp+8]
	int	60
	nop
	pop	ebp
	ret
none:
	nop
	jmp	$
	nop
	ret


;------------memcpy(dest,src,size)----------------
memcpy:
	push	ebp
	mov	ebp,esp
	push	esi
	push	edi
	mov	edi,[ebp+8]
	mov	esi,[ebp+12]
	mov	ecx,[ebp+16]
	cld
	rep	movsb
	pop	edi
	pop	esi
	pop	ebp
	ret
;-----------dispChar(char c)----------------------
dispChar:
	push 	ebp
	mov		ebp,esp
	push	edi
	xor		eax,eax
	mov		edi,dword[position]
	mov		al,byte[ebp+8]
	mov		ah,0ch
	mov		[gs:edi],eax
	add 	edi,2
	mov		dword[position],edi
	pop		edi
	pop		ebp
	ret	
;-----------dispStr(char* str)--------------------
dispStr:
	push	ebp
	mov	ebp,esp
	push	esi
	push	edi
	xor	eax,eax
	mov	esi,[ebp+8]
	cld
	mov	edi,dword[position]
.2:	lodsb
	test	al,al
	jz	.1
	cmp	al,0Ah
	jnz	.3
	mov	eax,edi
	mov	bl,160
	div	bl
	and	eax,0xFF
	inc	eax
	mov	bl,160
	mul	bl
	mov	edi,eax
	jmp	.2
.3:	mov	ah,0ch
	mov 	[gs:edi],ax
	add	edi,2
	jmp	.2
.1	mov	dword[position],edi
	pop	edi
	pop	esi
	pop	ebp
	ret
in_byte:
	;------int_byte(u16 port)-----------
	push	ebp
	mov	ebp,esp
	mov	edx,[ebp+8]
	xor	eax,eax
	in	al,dx
	nop
	nop
	pop	ebp
	ret
out_byte:
	;-------out_byte(u16 port,u8 data)----
	push	ebp
	mov	ebp,esp
	mov	edx,[ebp+8]
	xor	eax,eax
	mov	eax,[ebp+12]
	out	dx,al
	nop
	nop
	pop	ebp
	ret
cli:
	cli
sti:
	sti
	
